package com.situ.crm.controller;

import java.text.SimpleDateFormat;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.crm.common.ServerResponse;
import com.situ.crm.entity.CustomerLoss;
import com.situ.crm.service.ICustomerLossService;

@Controller
@RequestMapping(value="/customerLoss")
public class CustomerLossController {
	@Autowired
	private ICustomerLossService customerLossService;
	
	//展示页面
	@RequestMapping(value="/getCustomerLossPage")
	public String getCustomerLossPage() {
		return "customer_loss/customerLoss_list";
	}
	
	//展示
	@RequestMapping(value="/pageList")
	@ResponseBody
	public ServerResponse pageList(Integer page,Integer limit,CustomerLoss customerLoss) {
		ServerResponse serverResponse = customerLossService.pageList(page,limit,customerLoss);
		System.err.println(serverResponse);
		return serverResponse;
	}
	
	
	//删除功能
	@RequestMapping(value="/deleteById")
	@ResponseBody
	public ServerResponse deleteById(Integer id) {
		return customerLossService.deleteById(id);
	}
	
	//批量删除
	@RequestMapping(value="/deleteAll")
	@ResponseBody
	public ServerResponse deleteAll(String ids) {
		return customerLossService.deleteAll(ids);
	}
	
	//修改页面
    @RequestMapping(value="getUpdatePage")
	public String getUpdatePage(Integer id,Model model) {
    	CustomerLoss customerLoss = customerLossService.select(id);
    	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    	String xiadan = dateFormat.format(customerLoss.getLastOrderTime());
    	String liushi = dateFormat.format(customerLoss.getConfirmLossTime());
    	model.addAttribute("xiadan",xiadan);
    	model.addAttribute("liushi",liushi);
    	
    	model.addAttribute("customerLoss",customerLoss);
		return "customer_loss/customerLoss_update";
	}
    
    //修改
    @RequestMapping(value="/update")
    @ResponseBody
    public ServerResponse update(CustomerLoss customerLoss) {
    	System.err.println(customerLoss);
		return customerLossService.update(customerLoss);
	}
    
    //客户成功流失改状态
    @RequestMapping(value="/loser")
    @ResponseBody
    public ServerResponse loser(Integer id) {
		return customerLossService.upStatus(id);
	}
}
